/*
 * Copyright (c) 2020-2022. the original authors and DEPSEA.ORG
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.depsea.log.notification.link;

import lombok.extern.slf4j.Slf4j;
import org.depsea.log.notification.Message;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

/**
 * @author Wang Chengwei
 * @since 1.0.0 [2022/12/3 16:28]
 */
@Slf4j
public class LogLink implements Link {

    private final String baseUrl;

    public LogLink(String baseUrl) {
        this.baseUrl = baseUrl;
    }


    @Override
    public String getLinkName() {
        return "查看完整日志";
    }

    @Override
    public String getLinkUrl(Message message) {
        String url = this.baseUrl + "/app/discover";
        String encodeUrl = URLEncoder.encode(url, StandardCharsets.UTF_8);
        return "dingtalk://dingtalkclient/page/link?url=" + encodeUrl + "&pc_slide=false";
    }
}
